package com.verlet.servicehi.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author verlet
 * @date 2018/8/2
 */
@Slf4j
@RestController
@RequestMapping("/hello")
public class HelloController {

    @Value("${spring.application.name}")
    String serviceName;

    @Value("${server.port}")
    String port;

    private final RestTemplate restTemplate;

    public HelloController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @RequestMapping("/word")
    public String word(@RequestParam(value = "name", defaultValue = "hello word") String name) {
        log.info("calling trace {}",serviceName);
        return "hi " + name + ",i am form port: " + port;
    }

    @RequestMapping("/info")
    public String info() {
        log.info("calling trace {}",serviceName);
        return restTemplate.getForObject("http://service-ribbon/home", String.class);
    }

}
